package com.weblog.article.client.factory;


import com.weblog.article.client.UserClient;

import com.weblog.article.client.impl.UserClientImpl;
import entity.Result;
import entity.StatusCode;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author MaoLin Wang
 * @date 2019/10/2010:37
 */
@Component
public class UserFallBackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable throwable) {
        Logger logger= LoggerFactory.getLogger(UserFallBackFactory.class);
        throwable.printStackTrace();
        return new UserClientImpl() {

            @Override
            public Result findUserNameById(String id) {
                logger.error("文章调用户客户端出错了！Method=====findUserNameById",throwable.getMessage()==null?"":throwable.getMessage());

                return new Result(false, StatusCode.ERROR,"啊哦，文章调用用户客户端出现了异常");
            }

            @Override
            public Result isAccess(String targetRole, String targetPermission) {
                logger.error("文章调用户客户端出错了！Method=====isAccess",throwable.getMessage()==null?"":throwable.getMessage());

                return new Result(false, StatusCode.ERROR,"啊哦~文章调用用户客户端出错了");
            }

            @Override
            public Result incrScore(String id, int score) {
                logger.error("文章调用户客户端出错了！Method=====incrScore",throwable.getMessage()==null?"":throwable.getMessage());

                return new Result(false, StatusCode.ERROR,"啊哦~文章调用户客户端出错了");
            }

            @Override
            public Result articleInfo(String userId, String id) {
                logger.error("文章调用户客户端出错了！Method=====articleInfo",throwable.getMessage()==null?"":throwable.getMessage());
                return new Result(false, StatusCode.ERROR,"啊哦~文章调用户客户端出错了");
            }
        };
    }
}
